package com.tiantianyuegou.activity;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.tiantianyuegou.R;
import com.tiantianyuegou.constant.Constant;
import com.tiantianyuegou.util.Tools;

import java.io.FileInputStream;

/**
 * 查看图片
 * Created by ivany on 2016/1/19.
 */
public class CheckPhotoActivity extends BaseActivity implements View.OnClickListener {
    private ImageView mImg, mImg_delete;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_check_photo);
        Tools.changeSystemBar(this);
        setTitle("查看图片");
        initViews();
    }

    @Override
    public void findViewByIds() {
        mImg = (ImageView) findViewById(R.id.check_photo_img);
        mImg_delete = (ImageView) findViewById(R.id.check_photo_delete);
    }

    @Override
    public void initListener() {
        mImg_delete.setOnClickListener(this);
    }

    @Override
    public void initData() {
        String url = getIntent().getStringExtra("pic");
        Log.e("TAG", "photo url is:"+url);
//        mImg.setImageBitmap(decodeUriAsBitmap(url));
        ImageLoader.getInstance().displayImage(url,mImg);
    }

    private Bitmap decodeUriAsBitmap(String url) {

        Bitmap bitmap = null;
        try {
            FileInputStream fis = new FileInputStream(url);
            bitmap = BitmapFactory.decodeStream(fis);
        } catch (Throwable e) {
            e.printStackTrace();
            return null;
        }
        return bitmap;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.check_photo_delete:
                setResult(Constant.CHECK_PHOTO_RESULT,getIntent());
                finish();
                break;
        }
    }
}
